package com.company.huisuo.biz.dialog

import android.app.Activity
import androidx.appcompat.app.AppCompatActivity
import androidx.lifecycle.lifecycleScope
import com.company.huisuo.R
import com.company.huisuo.base.BaseCenterPopupView
import com.company.huisuo.databinding.DialogRewardSuccessBinding
import kotlinx.coroutines.Job
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch

/**
 * 打赏成功
 */
class RewardSuccessDialog(activity: Activity) : BaseCenterPopupView<DialogRewardSuccessBinding>(
    activity
) {
    private var mJob: Job? = null

    override val getLayoutId: Int
        get() = R.layout.dialog_reward_success
    override val getViewBinding: DialogRewardSuccessBinding
        get() = DialogRewardSuccessBinding.bind(contentView)

    override fun initData() {
        mJob = (activity as AppCompatActivity).lifecycleScope.launch {
            delay(2000)
            dismiss()
        }
    }

    override fun onDismiss() {
        super.onDismiss()
        if (mJob != null && mJob?.isActive == true) {
            mJob?.cancel()
        }
    }
}